package com.jhy.review.fuxi.day01;

/**
 * 复习 冒泡
 * 2022年10月31日21:45:32
 */
public class MaoPao {
    public static void BuddleSort(int[] arr) {
        if (arr.length < 2) {
            return;
        }
        for (int i = 0; i < arr.length; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if(arr[i]<arr[j]){
                    swap(i,j,arr);
                }
            }
        }
    }

    private static void swap(int i, int j, int[] arr) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static void main(String[] args) {
        int[] arr={2,1,3,1};
        long time = System.currentTimeMillis();
        BuddleSort(arr);
        long end = System.currentTimeMillis();
        System.out.println("时间："+(end-time));
        for (int i = 0; i <arr.length ; i++) {
            System.out.println(arr[i]);
        }

    }
}
